#include<stdio.h>
int a[30][30]={0};
int way(int x,int y);
int main()
{
	int xn,yn;
	while(scanf("%d%d",&xn,&yn)!=EOF)
	{
		for(int i=0;i<xn;i++)
			for(int j=0;j<yn;j++)
				scanf("%d",&a[i][j]);
		
		printf("%d\n",way(xn-1,yn-1));
	}
	return 0;
}
int way(int x,int y)
{
	if(a[x][y]==1)
		return 0;
	if(x>0&&y>0)
		return way(x-1,y)+way(x,y-1);
	if(x>0)
		return way(x-1,y);
	if(y>0)
		return way(x,y-1);
	return 1;
}
